package com.apexedu.identity.action;

import java.util.List;

import com.apexedu.biz.Const;
import com.apexedu.biz.entity.TServiceCodesort;
import com.apexedu.biz.entity.TServiceIntroducd;
import com.apexedu.framework.util.ConfigUtil;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.identity.entity.TSysMenu;
import com.apexedu.identity.service.IdMenuService;
import com.apexedu.portal.constant.Constants;
import com.apexedu.sys.action.AbstractBaseActionSupport;
import com.apexedu.sys.entity.ApplicationEnum;

public class IdMenuAction extends AbstractBaseActionSupport {

	/**
	 * 希望类的不同版本对序列化兼容，只要确保类的不同版本具有相同的serialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	private TSysMenu tsysMenu;
	private List<TSysMenu> tsysMenues;
	private String services;
	private List<String> listIcon; //图标名集合

	private TServiceIntroducd tserviceintroducd;

	private String serviceid;

	private List<TServiceCodesort> tservicecodesortList;

	/** 项目代码 */
	private String projectCode;
	/** 项目代码-山东大学 */
	private String projectCode_sddx = Constants.ProjectInfo.PROJECT_CODE_SDDX;

	public String getProjectCode_sddx() {
		return projectCode_sddx;
	}

	public void setProjectCode_sddx(String projectCode_sddx) {
		this.projectCode_sddx = projectCode_sddx;
	}

	public String getProjectCode() {
		return projectCode;
	}

	public void setProjectCode(String projectCode) {
		this.projectCode = projectCode;
	}

	public String execute() {

		return toView("execute.jsp");
	}

	public void copyNode() {
		IdMenuService service = (IdMenuService) getBaseService();
		try {
			String res = service.copyNode(tsysMenu);
			putResultStringToView(res);
		} catch (Exception e) {
			putResultStringToView(e.getMessage());
		}
	}

	public void moveNode() {
		IdMenuService service = (IdMenuService) getBaseService();
		try {
			String res = service.moveNodeBySTA(tsysMenu);
			putResultStringToView(res);
		} catch (Exception e) {
			putResultStringToView(e.getMessage());
		}
	}

	/**
	 * 添加服务到门户
	 */
	public void addPortal() {
		IdMenuService service = (IdMenuService) getBaseService();
		try {
			service.addPortal(tsysMenu);
			putResultStringToView("ok");
		} catch (Exception e) {
			e.getMessage();
			putResultStringToView(e.getMessage());
		}
	}

	/**
	 * 批量添加服务到门户
	 *
	 * @return
	 */
	public String batchadd() {
		getRequest().setAttribute("wid", getRequest().getParameter("wid"));
		return toView("batchadd.jsp");
	}

	/**
	 * 获取业务系统服务
	 *
	 * @return
	 */
	public void getMenues() {
		IdMenuService service = (IdMenuService) getBaseService();
		try {
			putResultStringToView(service.getMenus());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void saveBatchService() {
		IdMenuService service = (IdMenuService) getBaseService();
		try {
			service.saveBatchService(getRequest().getParameter("menuids"), getRequest().getParameter("upmenuid"));
			putResultStringToView("ok");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取
	 *
	 * @return
	 */
	public List<ApplicationEnum> getServiceMenu() {
		String sql = "select t.menuid as id,t.menuname as caption from T_SYS_MENU t where t.belongtoapp = ? and length(t.menuid) = ? order by ordernum desc";
		return DBUtil.queryAllBeanList(sql, ApplicationEnum.class, ConfigUtil.getString("portalCode"), Const.PortalMenuLength.MENU_TYPE);
	}

	public TSysMenu getTsysMenu() {
		return tsysMenu;
	}

	public void setTsysMenu(TSysMenu tsysMenu) {
		this.tsysMenu = tsysMenu;
	}

	public List<TSysMenu> getTsysMenues() {
		return tsysMenues;
	}

	public void setTsysMenues(List<TSysMenu> tsysMenues) {
		this.tsysMenues = tsysMenues;
	}

	public List<String> getListIcon() {
		return listIcon;
	}

	public void setListIcon(List<String> listIcon) {
		this.listIcon = listIcon;
	}

	public List<TServiceCodesort> getTservicecodesortList() {
		return tservicecodesortList;
	}

	public void setTservicecodesortList(List<TServiceCodesort> tservicecodesortList) {
		this.tservicecodesortList = tservicecodesortList;
	}

	public String getServiceid() {
		return serviceid;
	}

	public void setServiceid(String serviceid) {
		this.serviceid = serviceid;
	}

	public String getServices() {
		return services;
	}

	public void setServices(String services) {
		this.services = services;
	}

	public TServiceIntroducd getTserviceintroducd() {
		return tserviceintroducd;
	}

	public void setTserviceintroducd(TServiceIntroducd tserviceintroducd) {
		this.tserviceintroducd = tserviceintroducd;
	}
}
